package com.itheima.exerciseTest.method20_29.method29;

import java.util.concurrent.atomic.AtomicInteger;

public class FatherChristmas implements Runnable {
    private Warehouse w;

    public FatherChristmas(Warehouse w) {
        this.w = w;
    }

    private AtomicInteger ai = new AtomicInteger();

    @Override
    public void run() {
        while (true) {
            if (w.getGift() < 10) {
                break;
            }
            ai.getAndSet(w.getGift());
            w.setGift(ai.decrementAndGet());
            System.out.println(Thread.currentThread().getName() + "号圣诞老人送礼物,还剩 " + ai.get() + "个礼物");
        }
    }
}
